package org.example.day11;

import java.util.concurrent.locks.ReentrantLock;

/**
 * 4.1.10.1 方法getHoldCount()、getQueueLength()和getWaitQueueLength()测试
 *      方法getHoldCount(): 获取锁的嵌套层数
 *          the number of holds on this lock by the current thread,
 *          or zero if this lock is not held by the current thread
 */
public class MyThread7 {
    private ReentrantLock lock = new ReentrantLock();
    public void serviceMethod(){
        try {
            lock.lock();
            System.out.println("A getHoldCount()" + lock.getHoldCount());
            serviceMethod2();
            System.out.println("C getHoldCount()" + lock.getHoldCount());
        } finally {
            lock.unlock();
        }
    }
    public void serviceMethod2(){
        try {
            lock.lock();
            System.out.println("B getHoldCount()" + lock.getHoldCount());
        } finally {
            lock.unlock();
        }
    }

    public static void main(String[] args) {
        MyThread7 m7 = new MyThread7();
        m7.serviceMethod();
    }
}
